﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace SerivceMonitorFrom
{
    public class SMS短信管理
    {
        public bool 发送短信(string 发送内容, string 手机号)
        {
            string username = "huhuikeji";
            string pwd = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("DrNk13F28m"));//密码要Base64编码
            string urltem = "http://61.147.98.117:9001/servlet/UserServiceAPI";
            //string urltem = "http://61.147.98.117:9015/servlet/UserServiceAPI";
            string method = "sendSMS";
            string mobile = 手机号;
            //先GBK编码,然后UrlEncode编码
            string content = HttpUtility.UrlEncode(Encoding.GetEncoding("GBK").GetBytes(发送内容));
            string url = urltem + "?method=" + method + "&isLongSms=0&username=" + username + "&password=" + pwd +
                         "&smstype=1&mobile=" + mobile + "&content=" + content;
            WebRequest myRequest = WebRequest.Create(url);
            WebResponse myResponse = myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream());
            var result = reader.ReadToEnd().ToLower();
            return result.IndexOf("Success".ToLower(), StringComparison.Ordinal) > -1;
        }
    }
}
